function graph(type)

switch type
case {"tran"}

[d,h]=spice_readfile('rawspice_tran.raw');

time = d(:,cellidx(h,'time'));

subplot(2,2,1)
idx= cellidx(h,{'v(la)','v(ra)'});
plot(time,d(:,idx(1))-d(:,idx(2)))
xlabel('time (s)')
ylabel('voltage (V)')
title('Transient Analysis (Input)')
axis tight

subplot(2,2,2)
plot(time,d(:,cellidx(h,'v(vout1)')))
xlabel('time (s)')
ylabel('voltage (V)')
title('Transient Analysis (Instrumental Amplifier Output)')

subplot(2,2,3)
plot(time,d(:,cellidx(h,'v(vout2)')))
xlabel('time (s)')
ylabel('voltage (V)')
title('Transient Analysis (Highpass filter output)')

subplot(2,2,4)
plot(time,d(:,cellidx(h,'v(vout)')))
xlabel('time (s)')
ylabel('voltage (V)')
title('Transient Analysis (Lowpass filter output)')
axis tight

%subplot(3,2,5)
%plot(time,d(:,cellidx(h,'v(vout)')))
%axis(time_interval)
%xlabel('time (s)')
%ylabel('voltage (V)')
%title('Transient Analysis (Notch Filter Output)')


print -dpng graph_tran.png

case {"ac"}

[d,h]=spice_readfile('rawspice_ac.raw');
freq = d(:,cellidx(h,'frequency'));
vin = d(:,cellidx(h,'v(vout1)'));
vout = d(:,cellidx(h,'v(vout)'));
gain = vout ./ vin;
gain_db = 10*log10(abs(gain));

subplot(2,2,1)
semilogx(freq,gain_db)
xlabel('Frequency (Hz)'),ylabel('Gain (dB)')
title('AC Analysis (Filters)')
grid on

subplot(2,2,2)
plot(freq,abs(gain_db))
xlabel('Frequency (Hz)'),ylabel('Gain')
xlim([0 200])
grid on

subplot(2,2,3)
semilogx(freq,arg(gain))
xlabel('Frequency (Hz)'),ylabel('Phase Shift (Rad)')
grid on

subplot(2,2,4)
plot(freq,arg(gain))
xlabel('Frequency (Hz)'),ylabel('Phase Shift (Rad)')
xlim([0 200])
grid on

print -dpng graph_ac.png

endswitch
endfunction
